/* contains shared server/client engine backbone parts */

#include <allegro.h>
#include "main.h"
#include "resources.h"

BITMAP* buffer;
int quit;

void flip()
{
	blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);
	#if TOWERHACK_DEBUG_DUNGEON
	clear_bitmap (buffer);
	#endif
}

volatile int ticks = 0; 
void timer(void)
{
	ticks++;
}

void load_allegro ()
{
	allegro_init();
	install_keyboard();
	install_timer();
	install_mouse();
	enable_hardware_cursor (); // TODO: check capabilities?
	set_color_depth(32);
	set_alpha_blender();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, WIDTH, HEIGHT, 0, 0);
	buffer = create_bitmap(SCREEN_W, SCREEN_H);
	install_int_ex(timer, BPS_TO_TIMER(FPS));
}

void load_data ()
{
	resources_load();
	set_mouse_sprite (bmp.cursor);
}

void cleanup ()
{
	resources_unload();
	destroy_bitmap(buffer);
	allegro_exit();
}
